Skip to content

Conversation

@susanharper-okta
Copy link
Contributor

@susanharper-okta susanharper-okta commented Dec 18, 2025

Description:

  • What's changed? Sign in mobile users with a self-hosted page doc
  • Is this PR related to a Monolith release? No

Netlify
https://preview-5880--reverent-murdock-829d24.netlify.app/docs/guides/sign-users-in-mobile-self-hosted/main/

Resolves:

@okta-prod-github-app

This comment was marked as outdated.

@eng-info-dev-github-bot

Netlify Preview URL for the changes: https://preview-5880--reverent-murdock-829d24.netlify.app

layout: Guides
---

Add authentication to your mobile app using a self-hosted sign-in page with the Okta Client SDK.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Add authentication to your mobile app using a self-hosted sign-in page with the Okta Client SDK.
Add authentication to your mobile app using a self-hosted sign-in page with the Okta Client SDK for Swift.


## Build the authentication service

With setup complete, implement the core authentication logic and create a service layer that handles all interactions with the Okta DirectAuth API.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
With setup complete, implement the core authentication logic and create a service layer that handles all interactions with the Okta DirectAuth API.
With setup complete, implement the core authentication logic and create a service layer that handles all interactions with the [Okta DirectAuth API](https://okta.github.io/okta-mobile-swift/development/documentation/oktadirectauth/).


**State management**: The service maintains the current authentication state (idle, authenticating, authenticated, or error), allowing your UI to respond appropriately. This state-driven approach makes it easy to show loading indicators, error messages, or authenticated content.

**Security best practices**: All token handling and storage is managed through the service, ensuring that credentials are stored securely in the iOS keychain through `AuthFoundation`. Your UI never directly touches sensitive data.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**Security best practices**: All token handling and storage is managed through the service, ensuring that credentials are stored securely in the iOS keychain through `AuthFoundation`. Your UI never directly touches sensitive data.
**Security best practices**: All token handling and storage is managed through the service, ensuring that credentials are stored securely in the iOS keychain through [`AuthFoundation`](https://okta.github.io/okta-mobile-swift/development/documentation/authfoundation/). Your UI never directly touches sensitive data.


**Security best practices**: All token handling and storage is managed through the service, ensuring that credentials are stored securely in the iOS keychain through `AuthFoundation`. Your UI never directly touches sensitive data.

**Testability**: By defining a protocol (AuthServicing), you can easily create mock implementations for unit testing your views without making actual network calls to Okta.
Copy link
Contributor

@brentschaus-okta brentschaus-okta Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**Testability**: By defining a protocol (AuthServicing), you can easily create mock implementations for unit testing your views without making actual network calls to Okta.
**Testability**: By defining a protocol (`AuthServicing`), you can easily create mock implementations for unit testing your views without making actual network calls to Okta.

// MARK: - Authentication Methods

func authenticate(username: String, password: String) async throws {
// 1️⃣ Update state to show authentication is in progress
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we starting to use these number icons now? I don't think we use them anywhere else.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It took me a minute to realize that the numbers in the code correspond to the numbers that follow. Once I got it, I see that it works well. But it wasn't clear to me at first.


If the network request fails or the token is invalid, return `nil` rather than crashing. The calling code can decide how to handle the missing data.

### Complete AuthService code
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because "complete" can also be a verb, this threw me for a minute. Would it be okay to write it like "Full AuthService code" or "The full AuthService code"?

// MARK: - Authentication Methods

func authenticate(username: String, password: String) async throws {
// 1️⃣ Update state to show authentication is in progress
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is the full code, and the dev has already (presumably) walked through the "understand" sections, should we drop the numbers from the "full code sample"?

}
```

With the `AuthService` complete, you now have a robust authentication layer that handles the sign-in and sign-out flows, token management, and user profile retrieval. This service forms the foundation of your app's security, and because it's protocol-based, it's easy to test and maintain.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This content almost gets buried at the end of the sample. What if you put it up under the "Complete code" header, before the full sample?

```

## How they work together

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that this is a good sum-up of the flow, but I wonder if a version of this wouldn't serve better towards the beginning of the guide?


1. **Build and run**: Press `Cmd+R` to build and run your app in the simulator.
1. **Enter credentials**: Use valid Okta user credentials from your org.
1. **Sign in**: Tap **Sign In**.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a funny one :)

I know that they're running the sim, but presumably they're running it in Xcode so they're clicking it. But they're simulating a tap.

1. **Sign in**: Tap **Sign In**.
1. **View token**: After successful authentication, your access token appears.
1. **Explore features**:
* Tap **View Profile** to see user information.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with these. I think that they're clicking, rather than tapping. The simulation runs in the IDE and they're using the pointer with their mouse to click.

Please note: this is by no means a hill I'm prepared to die on haha

**Token expiration**<br>
Access tokens typically expire after one hour. Use the **Refresh Token** button to get a new one without reauthenticating.

## Understand session persistence
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we put this up where we have "Implement the AuthService"? Not sure why this is dropped down below the troubleshooting content.


The `AuthFoundation` library stores tokens securely in the iOS keychain, which persists across app launches. This creates a seamless experience while maintaining security.

## Security considerations
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be towards the beginning of the doc near the Overview section? Seems important and risks getting lost at the end of a long guide.


* **Error handling**: Provide clear error messages without exposing sensitive security details.

## Beyond username and password
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with this content.

Copy link
Contributor

@brentschaus-okta brentschaus-okta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Some suggested edits and a few questions. Please let me know what you think :)

@okta-prod-github-app
Copy link

Acrolinx score

A minimum Acrolinx Score of 80 is required. The total score is an average of the subscores.
Select Total score to review the Acrolinx scorecard for your article. Try to increase your individual scores, for example: Correctness. Your content will be clearer and more consistent.

Article Total score
Required:80
Word and phrases
(Brand, terms)
Preferred: 80
Correctness
(Spelling, grammar)
Preferred: 80
Clarity
(Readability)
Preferred: 80
Inclusive language
(+ accesibility)
Preferred: 80
packages/@okta/vuepress-site/docs/guides/index.md 91 100 89 78 100
packages/@okta/vuepress-site/docs/guides/sign-users-in-mobile-self-hosted/index.md 87 100 100 14 100
packages/@okta/vuepress-site/docs/guides/sign-users-in-mobile-self-hosted/main/index.md 89 93 72 100 100

Successfully checked 3 of 3 documents.
See summary in Content Analysis Dashboard

Reopen the pull request or push new changes to check again.

Depending on the Acrolinx server configuration, the
links expire after some time and you must have a login for the
Acrolinx server to access them again.

Copy link
Contributor

@brentschaus-okta brentschaus-okta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!


* **Use only HTTPS**: Ensure that all API calls use secure connections. Okta enforces this by default.

* **Consider adding MFA**: Password-only authentication is less secure than password + MFA. Consider adding support for more factors as your app matures.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* **Consider adding MFA**: Password-only authentication is less secure than password + MFA. Consider adding support for more factors as your app matures.
* **Consider adding MFA**: Password-only authentication is less secure than password + MFA. Consider adding support for more authenticators as your app matures.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is OIE, I think this should be authenticators instead of factors

Copy link
Contributor

@grahamsmith-okta grahamsmith-okta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few comments


* **Use only HTTPS**: Ensure that all API calls use secure connections. Okta enforces this by default.

* **Consider adding MFA**: Password-only authentication is less secure than password + MFA. Consider adding support for more factors as your app matures.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is OIE, I think this should be authenticators instead of factors


### Understand the AuthService architecture

The `AuthService` is the heart of our authentication system. It serves as a centralized layer that manages the entire authentication lifecycle, from the initial sign-in flow to session maintenance. By encapsulating all authentication logic in a single service, Okta achieves several important goals:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The `AuthService` is the heart of our authentication system. It serves as a centralized layer that manages the entire authentication lifecycle, from the initial sign-in flow to session maintenance. By encapsulating all authentication logic in a single service, Okta achieves several important goals:
The `AuthService` is the heart of Okta's authentication system. It serves as a centralized layer that manages the entire authentication lifecycle, from the initial sign-in flow to session maintenance. By encapsulating all authentication logic in a single service, Okta achieves several important goals:


The `AuthService` is the heart of our authentication system. It serves as a centralized layer that manages the entire authentication lifecycle, from the initial sign-in flow to session maintenance. By encapsulating all authentication logic in a single service, Okta achieves several important goals:

**Separation of concerns**: The service isolates authentication logic from UI code, making it both easier to test and maintain. Your SwiftUI views don't need to know how direct authentication works, they simply call methods like `authenticate()` or `logout()`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**Separation of concerns**: The service isolates authentication logic from UI code, making it both easier to test and maintain. Your SwiftUI views don't need to know how direct authentication works, they simply call methods like `authenticate()` or `logout()`.
**Separation of concerns**: The service isolates authentication logic from UI code, making it easier to both test and maintain. Your SwiftUI views don't need to know how direct authentication works, they simply call methods like `authenticate()` or `logout()`.

}
```

This protocol defines the contract for our authentication service, making it easy to test and mock later.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This protocol defines the contract for our authentication service, making it easy to test and mock later.
This protocol defines the contract for the Okta authentication service, making it easy to test and mock later.


`ProfileView`: Display user information

After the user is authenticated, users want to see their profile information. The `ProfileView` performs the following actions:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
After the user is authenticated, users want to see their profile information. The `ProfileView` performs the following actions:
After the user is authenticated, they want to see their profile information. The `ProfileView` performs the following actions:

## Handle common issues

**Invalid credentials**<br>
If you see an authentication error, verify that:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If you see an authentication error, verify that:
If you see an authentication error, verify the following:

* The Resource Owner Password grant type is enabled in your authorization server

**Configuration errors**<br>
If the app crashes on launch:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If the app crashes on launch:
If the app crashes on launch, verify the following:

@okta-prod-github-app
Copy link

Acrolinx score

A minimum Acrolinx Score of 80 is required. The total score is an average of the subscores.
Select Total score to review the Acrolinx scorecard for your article. Try to increase your individual scores, for example: Correctness. Your content will be clearer and more consistent.

Article Total score
Required:80
Word and phrases
(Brand, terms)
Preferred: 80
Correctness
(Spelling, grammar)
Preferred: 80
Clarity
(Readability)
Preferred: 80
Inclusive language
(+ accesibility)
Preferred: 80
packages/@okta/vuepress-site/docs/guides/index.md 91 100 89 78 100
packages/@okta/vuepress-site/docs/guides/sign-users-in-mobile-self-hosted/index.md 87 100 100 14 100
packages/@okta/vuepress-site/docs/guides/sign-users-in-mobile-self-hosted/main/index.md 88 93 70 100 100

Successfully checked 3 of 3 documents.
See summary in Content Analysis Dashboard

Reopen the pull request or push new changes to check again.

Depending on the Acrolinx server configuration, the
links expire after some time and you must have a login for the
Acrolinx server to access them again.

@okta-prod-github-app
Copy link

Acrolinx score

A minimum Acrolinx Score of 80 is required. The total score is an average of the subscores.
Select Total score to review the Acrolinx scorecard for your article. Try to increase your individual scores, for example: Correctness. Your content will be clearer and more consistent.

Article Total score
Required:80
Word and phrases
(Brand, terms)
Preferred: 80
Correctness
(Spelling, grammar)
Preferred: 80
Clarity
(Readability)
Preferred: 80
Inclusive language
(+ accesibility)
Preferred: 80
packages/@okta/vuepress-site/docs/guides/index.md 91 100 89 78 100
packages/@okta/vuepress-site/docs/guides/sign-users-in-mobile-self-hosted/index.md 87 100 100 14 100
packages/@okta/vuepress-site/docs/guides/sign-users-in-mobile-self-hosted/main/index.md 88 93 70 100 100

Successfully checked 3 of 3 documents.
See summary in Content Analysis Dashboard

Reopen the pull request or push new changes to check again.

Depending on the Acrolinx server configuration, the
links expire after some time and you must have a login for the
Acrolinx server to access them again.

@susanharper-okta susanharper-okta merged commit 9f9bd39 into master Jan 16, 2026
4 checks passed
@susanharper-okta susanharper-okta deleted the sdh-okta1020096-OCIsignusersin branch January 16, 2026 18:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants